/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#include "WOWDbcFile.h"

namespace PQGame
{
	WOWDbcFile::~WOWDbcFile(void)
	{
		if(_buf){
			delete _buf;
		}
	}

	WOWDbcFile::WOWDbcFile(PQEngine::FileBase* file)
		: _buf(0)
	{
		assert(file);
		_fileName=file->getFileName();
		_fileSize=file->getSize();
		_buf=new unsigned char[_fileSize];
		memcpy(_buf,file->getBuffer(),_fileSize);

		init();
	}

	void WOWDbcFile::init()
	{
		_header=(WOWDbcHeader*)_buf;

		assert(_header->signature[0]=='W' && _header->signature[1]=='D' 
			&& _header->signature[2]=='B' && _header->signature[3] == 'C');
		
		assert(_header->fields*4 == _header->recordSize);

		_data=_buf+sizeof(WOWDbcHeader);
		_strTable=_data+_header->recordSize*_header->records;
	}


}
